package cn.newhopedairy.delivery.api;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Neo.Li
 * @date 2021-01-1415:20
 */
@Slf4j
@RestController
public class TestOauth2Controller {
    @GetMapping("/resource")
    public String resource(@AuthenticationPrincipal Jwt jwt) {
        log.debug("***** JWT Headers: {}", jwt.getHeaders());
        log.debug("***** JWT Claims: {}", jwt.getClaims().toString());
        log.debug("***** JWT Token: {}", jwt.getTokenValue());
        return String.format("Resource accessed by: %s (with subjectId: %s)" ,
                jwt.getClaims().get("user_name"),
                jwt.getSubject());
    }

}
